﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Drawing;  
namespace WinApi
{
    public static partial class Win32Api
    {
        /// <summary>
        /// 消息发送API
        /// </summary>
        /// <param name="hWnd">接受消息句柄</param>
        /// <param name="Msg">消息值ID</param>
        /// <param name="wParam">参数1</param>
        /// <param name="lParam">参数2</param>
        /// <returns></returns>
        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        public static extern IntPtr SendMessage(IntPtr hWnd, Int32 Msg, IntPtr wParam, IntPtr lParam);
        
        /// <summary>
        /// 发送消息
        /// </summary>
        /// <param name="hWnd">接受消息的句柄</param>
        /// <param name="Msg">消息值ID</param>
        /// <param name="wParam">参数1</param>
        /// <param name="lParam">参数2</param>
        /// <returns></returns>
        public static IntPtr SendMessage(IntPtr hWnd, Int32 Msg, IntPtr wParam, object lParam)
        {
            GCHandle gch = GCHandle.Alloc(lParam);
            IntPtr wnd = SendMessage(hWnd, Msg, IntPtr.Zero, (IntPtr)gch);
            gch.Free();
            return wnd;
        }
        /// <summary>
        /// 获得包含指定点的窗口的句柄
        /// </summary>
        /// <param name="p">指定点</param>
        /// <returns></returns>
        [DllImport("user32.dll")]
        public static extern IntPtr WindowFromPoint(Point p);
    }
    
}
